<?php

class bbwidgetmodule {
	function name() { return "BB Module Widget"; }
	function description() { return "BB module widget on homepage"; }
	function author() { return "Immanuel192"; }
	
	function hasSources() { return true; }
	function hasContent() { return true; }
	function hasViews() { return true; }
	
	function supportsWorkflow() { return false; }
	
	function permissions($internal = "") {
		return array(
			'administrate'=>'Administrate',
			'configure'=>'Configure',
			'manage'=>'Manage Articles',
		);
	}
		
	function show($view,$loc = null, $title = "") {
		// set page to 0
		$_REQUEST['page']=1;
		$_REQUEST['flow_has_set']=1; // to compatipility with view_page
		exponent_flow_set(SYS_FLOW_PUBLIC,SYS_FLOW_SECTIONAL);
		include("actions/view_page.php");
	}
	
	function deleteIn($loc) {
		global $db;
		$db->delete('article',"location_data='".serialize($loc)."'");
		$db->delete('category', "location_data='".serialize($loc)."'");
		$db->delete('articlemodule_config', "location_data='".serialize($loc)."'");
	}
	
	function copyContent($oloc,$nloc) {
		global $db;
		$catid_map = array();
		
		foreach ($db->selectObjects('category',"location_data='".serialize($oloc)."'") as $category) {
			$oldid = $category->id;
			unset($category->id);
			$category->location_data = serialize($nloc);
			$catid_map[$oldid] = $db->insertObject($category,'category');
		}
		
		foreach ($db->selectObjects('article',"location_data='".serialize($oloc)."'") as $object) {
			unset($object->id);
			$object->location_data = serialize($nloc);
			if (isset($catid_map[$object->category_id])) {
				$object->category_id = $catid_map[$object->category_id];
			} else {
				$object->category_id = 0;
			}
			$db->insertObject($object,'article');
		}
		
		
		$conf = $db->selectObject('articlemodule_config', "location_data='".serialize($oloc)."'");
		unset($conf->id);
		$conf->location_data = serialize($nloc);
		$db->insertObject($conf,'articlemodule_config');
	}
}

?>
